/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaIngrediente.java
 *
 * Created on 06/04/2011, 01:04:53 AM
 */

package vistas;

import controladores.ControladorIngrediente;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.util.LinkedList;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author usuario
 */
public class VistaIngrediente extends javax.swing.JFrame {

    private ControladorIngrediente control;
    /** Creates new form VistaIngrediente */
    public VistaIngrediente() {
        initComponents();
        control= new ControladorIngrediente(this);
        limpiar();
        addAction();
    }
    
    public void mostrarMensaje(String mensaje){
        JOptionPane.showMessageDialog(new JFrame(),mensaje,"Cari Burger",JOptionPane.INFORMATION_MESSAGE);

    	
    }
    
    public void windowClosing(WindowEvent e){
		setVisible(false);
	}

    public void addListener(ActionListener escuchador){
        btnSalir.addActionListener(escuchador);
        btnActualizar.addActionListener(escuchador);
        btnCancelar.addActionListener(escuchador);
        btnBuscar.addActionListener(escuchador);
        btnRegistrar.addActionListener(escuchador);
    }

     public void addAction(){
        btnSalir.setActionCommand("Salir");
        btnRegistrar.setActionCommand("Registrar");
        btnCancelar.setActionCommand("Cancelar");
        btnActualizar.setActionCommand("Actualizar");
        btnBuscar.setActionCommand("Buscar");
    }

    public boolean hayVacios(){
        for (int i = 0; i < getTextos().size(); i++) {
            JTextField texto = getTextos().get(i);
                JOptionPane.showMessageDialog(new JFrame(),"Campos vacios","Cari Burguer",JOptionPane.INFORMATION_MESSAGE);
                return true;
            }
       
        return false;
    }

    public boolean validoNumeros(){
        try{
            if(Double.parseDouble(txtCodigo.getText())<=0){
                txtCodigo.setText("");
                JOptionPane.showMessageDialog(new JFrame(),"El codigo es invalido","Cari Burguer",JOptionPane.WARNING_MESSAGE);
                return false;
           }
            if(Double.parseDouble(txtStock.getText())<0){
                txtCodigo.setText("");
                JOptionPane.showMessageDialog(new JFrame(),"El stock es invalido","Cari Burguer",JOptionPane.WARNING_MESSAGE);
                return false;
           }
             if(Double.parseDouble(txtComprada.getText())<0){
                txtCodigo.setText("");
                JOptionPane.showMessageDialog(new JFrame(),"La cantidad es invalida","Cari Burguer",JOptionPane.WARNING_MESSAGE);
                return false;
           }
       }catch(NumberFormatException ex){
           JOptionPane.showMessageDialog(new JFrame(),"Ingreso letras en lugar de numeros","Cari Burguer",JOptionPane.WARNING_MESSAGE);
           return false;
       }
    return true;
    }

    public boolean validarCodigoVacio(){
        if(txtCodigo.getText().equals("")){
                JOptionPane.showMessageDialog(new JFrame(),"Codigo vacio","Calle el Hambre Arena Aplaza",JOptionPane.INFORMATION_MESSAGE);
                return false;
            }

        return true;
    }

    public void mostrar(){
        txtCodigo.setEditable(false);
        txtStock.setEditable(false);
        txtDescripcion.setEditable(false);
        txtComprada.setVisible(true);
        jLabel7.setVisible(true);
        txtComprada.setText("0");
    }

    
     public void limpiar(){
        txtCodigo.setText("");
        txtDescripcion.setText("");
        txtStock.setText("");
        txtStock.setEditable(true);
        txtCodigo.setEditable(true);
        txtDescripcion.setEditable(true);
        txtComprada.setVisible(false);
        jLabel7.setVisible(false);
        txtComprada.setText("0");
    }

    public LinkedList<JTextField> getTextos() {
        LinkedList<JTextField> v = new LinkedList<JTextField>();
        v.add(txtCodigo);
        v.add(txtComprada);
        v.add(txtDescripcion);
        v.add(txtStock);
        return v;
    }

    public JTextField getTxtCodigo() {
        return txtCodigo;
    }

    public JTextField getTxtComprada() {
        return txtComprada;
    }

    public JTextField getTxtDescripcion() {
        return txtDescripcion;
    }

    public JTextField getTxtStock() {
        return txtStock;
    }    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        txtStock = new javax.swing.JTextField();
        txtComprada = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        txtDescripcion = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        btnRegistrar = new javax.swing.JButton();
        btnBuscar = new javax.swing.JButton();
        btnActualizar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(56, 230, 16));
        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(null);

        txtStock.setFont(new java.awt.Font("Arial", 0, 13));
        jPanel1.add(txtStock);
        txtStock.setBounds(170, 90, 130, 30);

        txtComprada.setFont(new java.awt.Font("Arial", 0, 13));
        txtComprada.setText("0");
        jPanel1.add(txtComprada);
        txtComprada.setBounds(170, 130, 130, 30);

        jLabel6.setFont(new java.awt.Font("Monospaced", 1, 13));
        jLabel6.setText("Codigo:");
        jPanel1.add(jLabel6);
        jLabel6.setBounds(20, 10, 130, 30);

        jLabel5.setFont(new java.awt.Font("Monospaced", 1, 13)); // NOI18N
        jLabel5.setText("Stock:");
        jPanel1.add(jLabel5);
        jLabel5.setBounds(20, 90, 130, 30);

        jLabel1.setFont(new java.awt.Font("Monospaced", 1, 13)); // NOI18N
        jLabel1.setText("Descripcion:");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(20, 50, 140, 32);

        txtDescripcion.setFont(new java.awt.Font("Arial", 0, 13));
        jPanel1.add(txtDescripcion);
        txtDescripcion.setBounds(170, 50, 130, 32);

        jLabel7.setFont(new java.awt.Font("Monospaced", 1, 13));
        jLabel7.setText("Cantidad Comprada:");
        jPanel1.add(jLabel7);
        jLabel7.setBounds(20, 130, 170, 30);
        jPanel1.add(txtCodigo);
        txtCodigo.setBounds(170, 10, 130, 28);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(80, 50, 310, 180);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setLayout(null);

        btnRegistrar.setFont(new java.awt.Font("Monospaced", 1, 13));
        btnRegistrar.setText("Registrar");
        btnRegistrar.setPreferredSize(new java.awt.Dimension(80, 30));
        jPanel2.add(btnRegistrar);
        btnRegistrar.setBounds(10, 20, 120, 30);

        btnBuscar.setFont(new java.awt.Font("Monospaced", 1, 13));
        btnBuscar.setText("Buscar");
        btnBuscar.setPreferredSize(new java.awt.Dimension(80, 30));
        jPanel2.add(btnBuscar);
        btnBuscar.setBounds(150, 20, 120, 30);

        btnActualizar.setFont(new java.awt.Font("Monospaced", 1, 13));
        btnActualizar.setText("Actualizar");
        btnActualizar.setPreferredSize(new java.awt.Dimension(80, 30));
        jPanel2.add(btnActualizar);
        btnActualizar.setBounds(280, 20, 120, 30);

        btnCancelar.setFont(new java.awt.Font("Monospaced", 1, 13));
        btnCancelar.setText("Cancelar");
        btnCancelar.setPreferredSize(new java.awt.Dimension(80, 30));
        jPanel2.add(btnCancelar);
        btnCancelar.setBounds(90, 60, 120, 30);

        btnSalir.setFont(new java.awt.Font("Monospaced", 1, 13));
        btnSalir.setText("Salir");
        jPanel2.add(btnSalir);
        btnSalir.setBounds(250, 60, 120, 30);

        getContentPane().add(jPanel2);
        jPanel2.setBounds(30, 240, 410, 110);

        jLabel2.setFont(new java.awt.Font("Monospaced", 1, 15));
        jLabel2.setText("Registro de Ingredientes");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(130, 20, 230, 22);

        jLabel3.setBackground(new java.awt.Color(13, 70, 204));
        jLabel3.setOpaque(true);
        getContentPane().add(jLabel3);
        jLabel3.setBounds(0, 0, 490, 410);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-490)/2, (screenSize.height-431)/2, 490, 431);
    }// </editor-fold>//GEN-END:initComponents


    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VistaIngrediente().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActualizar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnRegistrar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtComprada;
    private javax.swing.JTextField txtDescripcion;
    private javax.swing.JTextField txtStock;
    // End of variables declaration//GEN-END:variables

}
